//
//  NSURLSessionTask+custom.m
//  KFD
//
//  Created by JIRENTIANXIANG on 6/6/15.
//  Copyright (c) 2015 KFD. All rights reserved.
//

#import "NSURLSessionTask+custom.h"

@implementation NSURLSessionTask (custom)

+(NSURLSessionDataTask*)dataTaskWithSession:(NSURLSession *)session request:(NSURLRequest*)request completionHandler:(KFDSessionTaskCompletionHandler)completionHandler
{
    return [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        if (!error&&completionHandler) {
            KFDResponseBody* responseBody=[KFDResponseBody responseBodyWithData:data];
            completionHandler(responseBody);
        }
    }];
}

+(NSURLSessionUploadTask*)uploadTaskWithSession:(NSURLSession *)session request:(NSURLRequest *)request data:(NSData*)data completionHandler:(KFDSessionTaskCompletionHandler)completionHandler
{
    return [session uploadTaskWithRequest:request fromData:data completionHandler:^(NSData * __nullable data, NSURLResponse * __nullable response, NSError * __nullable error) {
        if (!error&&completionHandler) {
            KFDResponseBody* responseBody=[KFDResponseBody responseBodyWithData:data];
            completionHandler(responseBody);
        }
    }];
}

@end
